package com.ie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.entity.Community;
import com.ie.service.CommunityService;
import com.ie.mapper.CommunityMapper;
import com.ie.service.UsersService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
* @author admin
* @description 针对表【community】的数据库操作Service实现
* @createDate 2025-03-02 22:16:12
*/
@Service
public class CommunityServiceImpl
        implements CommunityService {
    @Resource
    private CommunityMapper communityMapper;

    @Override
    public List<Community> getAllCommunity() {

        return communityMapper.getAllCommunity();
    }

    @Override
    public boolean deleteCommunity(String id) {

        return communityMapper.deleteCommunity(id);
    }

    @Override
    public boolean likeCommunity(String userid, String likeid) {
        //查询点赞没
        if (communityMapper.findlike(userid, likeid)) {
            //删数据
            communityMapper.unlikeCommunity(userid, likeid);

            //如果已经点赞了，就取消点赞
            communityMapper.jian(likeid);
            return false;
        } else {
            communityMapper.likeCommunity(userid, likeid);
            communityMapper.jia(likeid);
            return true;
        }

    }

    @Override
    public boolean unlikeCommunity(String userid, String likeid) {
        return communityMapper.findlike(userid, likeid);
    }

    @Override
    public void addCommunity(Community community) {
        community.setPublishDate(new Date());
        communityMapper.insert(community);
    }
}






